
/**
 * 把字符串改为金额的格式
 * @param num 金额 (Number)
 * @param decimal
 * @returns {string}xx,xxx,xxx,xxx.xx
 */
export function moneyFormat(num, decimal) {
  if (typeof num === "number") {
    num = String(num.toFixed(decimal || 2));
    let re = /(-?\d+)(\d{3})/;
    while (re.test(num)) num = num.replace(re, "$1,$2");
    return num;
  }
  return num;
}
